package com.yuju.controller.login;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.yuju.common.Result;
import com.yuju.controller.base.BaseController;
import com.yuju.enums.RegisterReturnCodeEnum;
import com.yuju.enums.ReturnStatusEnum;
import com.yuju.login.model.OpModel;
import com.yuju.login.service.IRegisterService;
import com.yuju.vo.login.OpVO;
/**
 * 
 * 类名：RegisterController  <br />
 *
 * 功能：注册
 *
 * @author : zhousc <br />
 * @Date : 2018年1月5日 下午2:47:12  <br />
 * @version : 1.1 <br />
 */
/**
 * 
 * 类名：RegisterController  <br />
 *
 * 功能：注册
 *
 * @author : zhousc <br />
 * @Date : 2018年1月5日 下午5:26:18  <br />
 * @version : 1.1 <br />
 */
@Controller
@RequestMapping("wxRegister")
public class RegisterController extends BaseController<OpVO, OpModel>{

	@Autowired
	private IRegisterService registerService;
	/**
	 * 
	 * 功能：账号注册<br/>
	 *
	 * @author zhousc
	 * @throws Exception 
	 * @Date 2018年1月5日 下午5:26:30 <br/>
	 */
	@RequestMapping("register")
	@ResponseBody
	public Result register(@RequestBody JSONObject obj) throws Exception {
		OpVO opVO = obj.toJavaObject(OpVO.class);
		
		Result result = new Result();
		int rows = registerService.register(convert(opVO));
		if (rows > 0) {
			result.setStatus(ReturnStatusEnum.SUCCESS.getCode());
			result.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
			result.setReturnCode(RegisterReturnCodeEnum.REGISTER_SUCCESS.getCode());
			result.setReturnMsg(RegisterReturnCodeEnum.REGISTER_SUCCESS.getDesc());
		} else {
			result.setStatus(ReturnStatusEnum.FAILURE.getCode());
			result.setMsg(ReturnStatusEnum.FAILURE.getDesc());
			result.setReturnCode(RegisterReturnCodeEnum.REGISTER_FAILURE.getCode());
			result.setReturnMsg(RegisterReturnCodeEnum.REGISTER_FAILURE.getDesc());
		}
		return result;
	}
}
